<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>地图导航</title>
  <style>
        * {
          margin: 0;
          padding: 0;
        }
        #container {
          width: 100%;
          height: 100vh;
          background-color: #fff;
        }

    </style>
</head>
<body>
<div id="container"></div>

<script type="text/javascript">
      window._AMapSecurityConfig = {
        securityJsCode: "1407cf5116cbc5cf00ef192fe9e6acd7",
      };
</script>
<script type="text/javascript"
        src="https://webapi.amap.com/maps?v=1.4.15&key=884994b3847b24760092896714f29dbf"></script>
<script type="text/javascript">
        var map = new AMap.Map("container", {
            zoom: 16, //级别
            center: [121.47592, 31.237687], //中心点坐标
        })

        function getLocation(lon, lat){
            //window.swift.alert(lon+" "+lat)
            //1. 重新定位当前的位置
            map.setZoomAndCenter(16,[lon,lat],true)

            //2. 提供4个最近位置
            map.plugin(['AMap.PlaceSearch'], function() {
                var PlaceSearchOptions = { //设置PlaceSearch属性
                    pageSize: 4, //每页结果数,默认10
                    pageIndex: 1, //请求页码，默认1
                    extensions: "base" //返回信息详略，默认为base（基本信息）
                };
                var MSearch = new AMap.PlaceSearch(PlaceSearchOptions); //构造PlaceSearch类
                AMap.event.addListener(MSearch, "complete", (result)=>{
                    //获取在【lon,lat】中心点位置并且以“街道”为关键词的最近4个兴趣点：result.poiList.pois
                   window.swift.receiveData(JSON.stringify(result?.poiList?.pois || []))
                }); //返回结果
                MSearch.searchNearBy('学', new AMap.LngLat(lon,lat)); //关键字查询
            });
        }

        window.onload=function(){
            if(window.swift){
                window.swift.getLocation()
            }
        }

</script>
</body>
</html>